package com.zyw.codegen;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zhangyw
 * @date 2017/3/13 18:02
 */
public class GenTable {
    private String catalog;
    private String schema;
    private String tableName; // 表名
    private String entityClassName; // po 类名
    private String daoClassName;

    public String getCatalog() {
        return catalog;
    }

    public void setCatalog(String catalog) {
        this.catalog = catalog;
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getEntityClassName() {
        return entityClassName;
    }

    public void setEntityClassName(String entityClassName) {
        this.entityClassName = entityClassName;
    }

    public String getDaoClassName() {
        return daoClassName;
    }

    public void setDaoClassName(String daoClassName) {
        this.daoClassName = daoClassName;
    }

    public String entityClassName() {
        if (entityClassName == null)
            return lineToHump(tableName);

        return entityClassName;
    }

    public String daoClassName(){
        if (daoClassName == null)
            return entityClassName() + "Dao";
        return daoClassName;
    }

    public String lineToHump(String str) {
        str = str.toLowerCase();
        Matcher matcher = Pattern.compile("_(\\w)").matcher(str);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
}
